package com.xnewtech.xplatform.swan.system.modular.sys.service.impl;

import com.xnewtech.xplatform.swan.system.modular.sys.mapper.SysDashBoardMapper;
import com.xnewtech.xplatform.swan.system.modular.sys.service.SysDashBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysDashBoardServiceTmpl implements SysDashBoardService {

    @Autowired
    private SysDashBoardMapper sysDashBoardMapper;

    @Override
    public List<Map<String, Object>> modulesStatistics() {
        return sysDashBoardMapper.modulesStatistics();
    }

    @Override
    public Map<String, Object> bizStatistics(String cycle) {
        Map<String,Object> map = new HashMap<>();
        List<String> dateList = new ArrayList<>();
        List<Map<String, Object>> data = new ArrayList<>();
        Map<String,Object> loginMap = new HashMap<>();
        loginMap.put("name","登录情况");
        List<String> loginList = new ArrayList<>();
        Map<String,Object> otherMap = new HashMap<>();
        otherMap.put("name","其他");
        List<String> otherList = new ArrayList<>();
        String dayNums = "7";
        if("1".equals(cycle)){
            dayNums="30";
        }

        List<Map<String, Object>> results = sysDashBoardMapper.bizStatistics(dayNums);
        if(results!=null && !results.isEmpty()){
            for(Map result:results){
                dateList.add(result.get("days").toString());
                loginList.add(result.get("login").toString());
                otherList.add(result.get("biz").toString());
            }
        }

        loginMap.put("data",loginList);
        otherMap.put("data",otherList);

        data.add(loginMap);
        data.add(otherMap);
        map.put("xAxisData",dateList);
        map.put("chartData",data);
        return map;
    }
}
